﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class chi_tiet_san_pham : System.Web.UI.Page
{
    protected string ten_tour;
    protected string mo_ta;
    protected string noi_dung;
    protected string gia_khuyen_mai;
    protected string gia_thi_truong;
    protected string anh_to;
    protected string so_ngay;
    protected string so_dem;
    protected string so_cho;
    protected string so_cho_da_dat;
    protected string ngay_khoi_hanh;
    protected string ngay_ket_thuc;
    string id;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] != null)
        {
            id = Request.QueryString["id"].ToString();
            Tour Tour = new Tour();
            ObjTour objTour = Tour.getTourByID(id);
            anh_to = objTour.Anh_to;
            mo_ta = objTour.Mo_ta_ngan;
            noi_dung = objTour.Noi_dung;
            gia_khuyen_mai = objTour.Gia_khuyen_mai.ToString();
            gia_thi_truong = objTour.Gia_thi_truong.ToString();
            so_ngay = objTour.So_ngay.ToString();
            so_dem = objTour.So_dem.ToString();
            so_cho = objTour.So_cho.ToString();
            so_cho_da_dat = objTour.So_cho_da_dat.ToString();
            ngay_khoi_hanh = objTour.Ngay_khoi_hanh;
            ngay_ket_thuc = objTour.Ngay_ket_thuc;

            ten_tour = objTour.Ten_tour;
            Page.Title = objTour.Ten_tour;
        }
        else
        {
            Response.Redirect("/");
        }
    }

    protected void ibtDatmua_Click(object sender, ImageClickEventArgs e)
    {
        Utils utils = new Utils();
        List<WebControl> lstWebcontrol=new List<WebControl>();
        lstWebcontrol.Add(txtsoluong);
        lb_messenger.Text = utils.checkDataType(lstWebcontrol);
        if (lb_messenger.Text == "")
        {
            List<ObjGioHang> lstGioHang = new List<ObjGioHang>();
            ObjGioHang objGioHang = new ObjGioHang();
            if (Session["gio_hang"] == null)
            {
            }
            else
            {
                lstGioHang = (List<ObjGioHang>)Session["gio_hang"];
            }
            objGioHang.Tour_id = int.Parse(id);
            objGioHang.Ten_tour = ten_tour;
            objGioHang.So_luong = int.Parse(txtsoluong.Text);

           
            if (gia_khuyen_mai != "")
            {
                if (gia_khuyen_mai == Constants.LIEN_HE)
                {
                    objGioHang.Gia = 0;
                }
                else
                    objGioHang.Gia = int.Parse(gia_khuyen_mai);
            }
            
            //kiem tra neu san pham co trong gio hang thi tang so luong
            foreach (ObjGioHang item in lstGioHang)
            {
                if (objGioHang.Tour_id == item.Tour_id)
                {
                    item.So_luong += objGioHang.So_luong ;
                    Session["gio_hang"] = lstGioHang;
                    Response.Redirect("/gio_hang.aspx");
                }
            }
            lstGioHang.Add(objGioHang);
            Session["gio_hang"] = lstGioHang;
            Response.Redirect("/gio_hang.aspx");
        }
    }
}